home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_01_02
/
1n02079a
< prev
next >
Wrap
Text File
|
1990-07-08
|
2KB
|
83 lines
/* inpause() waits for a keypress or a mouse button press, then returns */
/* the key if a keyboard entry was made, or <CR> if RIGHT mouse button was */
/* pressed, ASCII 127 for any other button. The value to return with a */
/* mouse button press was a hard choice for me. A '\0' is used for */
/* function keys and alternate keys like the cursor keys as the first */
/* of two arguments. An '\n' is not normally returned by the keyboard, */
/* because keyboards are by default opened as binary devices. So <CR> */
/* seemed the least objectionable value to use. 127 just seemed like a */
/* safe no-op. */
int inpause()
{
int c=127; /* default for LEFT BUTTON or BOTH BUTTONS */
mstruc m;
mouse_clear();
for(;;)
{
if(kbhit())
{
c=getch();
break;
}
m=button_read();
if(m.status) /* any button press will force a return */
{
if(m.status==RIGHT_BUTTON)
c=CARRIAGE_RETURN;
break;
}
}
return c;
}
/* mouse_gets() is a substitute for gets(), in which RIGHT_BUTTON is able */
/* to be detected as a carriage return. Like gets(), the string that */
/* is returned is null-terminated. */
char * mouse_gets(sptr)
char *sptr;
{
int i=0;
unsigned char c='\0';
mouse_clear();
while(c != CARRIAGE_RETURN)
{
if(button_read().status==RIGHT_BUTTON)
c = CARRIAGE_RETURN;
if(kbhit())
{
c=getche();
if(c==BACKSPACE)
{
putc(' ', stdout);
putc(BACKSPACE,stdout);
i--;
if(i<0)
i=0;
sptr[i]='\0';
}
else
{
if(c != CARRIAGE_RETURN)
{
sptr[i]=c;
i++;
}
}
}
}
sptr[i]='\0';
printf("\n");
return sptr;
}